using System;
using System.Collections.Generic;

namespace CheckoutCodeKata
{
    public class Items
    {
        private readonly Dictionary<string, int> _itemsQuantity = new Dictionary<string, int>();
        private readonly IPriceRule _priceRule;

        public Items(IPriceRule priceRule)
        {
            _priceRule = priceRule;
        }

        public void Add(string code)
        {
            if (!_itemsQuantity.ContainsKey(code))
            {
                _itemsQuantity.Add(code, 1);
                return;
            }
            _itemsQuantity[code]++;
        }

        public void CalculateTotal()
        {
            foreach (var item in _itemsQuantity)
            {
                _priceRule.CalculatePrice(item.Key, item.Value);
            }
        }

        public void Reset()
        {
            _itemsQuantity.Clear();
        }
    }
}